package com.skzh.equipment.service.impl;

import java.util.Date;
import java.util.List;

import com.skzh.common.utils.DateUtils;
import com.skzh.equipment.domain.Dock;
import com.skzh.equipment.mapper.DockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.skzh.equipment.mapper.DroneMapper;
import com.skzh.equipment.domain.Drone;
import com.skzh.equipment.service.IDroneService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 无人机信息Service业务层处理
 *
 * @author skzh
 * @date 2025-03-26
 */
@Service
public class DroneServiceImpl implements IDroneService {
    @Autowired
    private DroneMapper droneMapper;

    @Autowired
    private DockMapper dockMapper;

    /**
     * 查询无人机信息
     *
     * @param id 无人机信息主键
     * @return 无人机信息
     */
    @Override
    public Drone selectDroneById(Long id) {
        return droneMapper.selectDroneById(id);
    }

    /**
     * 查询无人机信息列表
     *
     * @param drone 无人机信息
     * @return 无人机信息
     */
    @Override
    @Transactional
    public List<Drone> selectDroneList(Drone drone) {
        return droneMapper.selectDroneList(drone);
    }

    /**
     * 新增无人机信息
     *
     * @param drone 无人机信息
     * @return 结果
     */
    @Override
    public int insertDrone(Drone drone) {
        if (drone.getBoundAirportId()==null||drone.getBoundAirportId()==0){
            drone.setBindStatus("0");
        }else {
            drone.setBindStatus("1");
        }
        drone.setCreateTime(DateUtils.getNowDate());
        return droneMapper.insertDrone(drone);
    }

    /**
     * 修改无人机信息
     *
     * @param drone 无人机信息
     * @return 结果
     */
    @Override
    public int updateDrone(Drone drone) {
        if (drone.getBoundAirportId()==null||drone.getBoundAirportId()==0){
            drone.setBindStatus("0");
        }else {
            drone.setBindStatus("1");
        }
        drone.setUpdateTime(DateUtils.getNowDate());
        return droneMapper.updateDrone(drone);
    }

    /**
     * 批量删除无人机信息
     *
     * @param ids 需要删除的无人机信息主键
     * @return 结果
     */
    @Override
    public int deleteDroneByIds(Long[] ids) {
        return droneMapper.deleteDroneByIds(ids);
    }

    /**
     * 删除无人机信息信息
     *
     * @param id 无人机信息主键
     * @return 结果
     */
    @Override
    public int deleteDroneById(Long id) {
        return droneMapper.deleteDroneById(id);
    }
}
